package com.huanghuai.retail.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huanghuai.retail.common.R;
import com.huanghuai.retail.entity.RcDistrict;
import com.huanghuai.retail.service.RcDistrictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@RestController
@RequestMapping("/rcDistrict")
public class RcDistrictController {
    @Autowired
    private RcDistrictService rcDistrictService;

    @GetMapping("/province")
    public R<List<RcDistrict>> getProvince() {
        LambdaQueryWrapper<RcDistrict> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RcDistrict::getLevel,1);
        queryWrapper.orderByAsc(RcDistrict::getDistrictId);
        return R.success(rcDistrictService.list(queryWrapper));
    }
    @GetMapping("/city/{id}")
    public R<List<RcDistrict>> getCity(@PathVariable("id") Integer id) {
        return R.success(rcDistrictService.list(new LambdaQueryWrapper<RcDistrict>().eq(RcDistrict::getLevel, 2).eq(RcDistrict::getPid, id)));
    }
    @GetMapping("/area/{id}")
    public R<List<RcDistrict>> getArea(@PathVariable("id") Integer id) {
        return R.success(rcDistrictService.list(new LambdaQueryWrapper<RcDistrict>().eq(RcDistrict::getLevel, 3).eq(RcDistrict::getPid, id)));
    }

}
